
--drop assembly objects (links)
DECLARE @nsql NVARCHAR(MAX)

SET @nsql = ''

SELECT @nsql = @nsql
 + 'DROP ' + CASE		--http://msdn2.microsoft.com/en-us/library/ms190324.aspx
	WHEN o.type IN ('AF') THEN 'AGGREGATE'
	WHEN o.type IN ('FS') THEN 'FUNCTION'
	WHEN o.type IN ('FT') THEN 'FUNCTION'
	WHEN o.type IN ('TA') THEN 'TRIGGER'
	WHEN o.type IN ('PC') THEN 'PROCEDURE'
	ELSE 'UNKNOWN_OBJECT_TYPE'
END + ' ' + CASE
	WHEN sch.schema_id IS NOT NULL THEN '[' + sch.name + '].'
	ELSE ''
END + '[' + o.[name] + ']' + CHAR(13) + CHAR(10)
FROM sys.assemblies AS a
JOIN sys.assembly_modules AS am
ON am.assembly_id = a.assembly_id
JOIN sysobjects AS o
ON o.[id] = am.[object_id]
JOIN sys.objects AS so
ON so.[object_id] = o.[id]
JOIN sys.schemas AS sch
ON sch.schema_id = so.schema_id
WHERE a.[name] = 'FileSystem'

EXEC(@nsql)

-- drop assembly
IF EXISTS (
	SELECT *
	FROM sys.assemblies
	WHERE [name] = 'FileSystem'
)
DROP ASSEMBLY [FileSystem];
GO

-- create assembly
CREATE ASSEMBLY [FileSystem]
FROM 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C0103005980CB4B0000000000000000E00002210B010800001C00000006000000000000BE3B0000002000000040000000004000002000000002000004000000000000000400000000000000008000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000703B00004B000000004000001803000000000000000000000000000000000000006000000C00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E74657874000000C41B000000200000001C000000020000000000000000000000000000200000602E72737263000000180300000040000000040000001E0000000000000000000000000000400000402E72656C6F6300000C0000000060000000020000002200000000000000000000000000004000004200000000000000000000000000000000A03B0000000000004800000002000500442500002C1600000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000133004005400000001000011026F1100000A183323026F1200000A17937E1300000A3314027E1400000A8C18000001281500000A10002B21026F1100000A19311802178D180000010A06167E1400000A9D066F1600000A100002281700000A2A13300700360000000100001172010000700228010000067E1400000A8C1800000103178D180000010A06167E1400000A9D066F1800000A281900000A28010000062A4A0F00281B00000A2801000006281C00000A2A660F00281B00000A0F01281B00000A2802000006281C00000A2A5E0F00281B00000A2801000006281D00000A281C00000A2A5E0F00281B00000A281E00000A6F1F00000A281C00000A2A0013300300BC0000000200001102740100001B0A0306169AA51D000001520406179A7416000001510506189A7416000001510E0406199A7416000001510E05061A9A7416000001510E06061B9A7416000001510E07061C9A7416000001510E08061D9A7416000001510E09061E9A7416000001510E0A061F099AA51E000001550E0B061F0A9A7416000001510E0C061F0B9AA51D000001520E0D061F0C9AA50300000181030000010E0E061F0D9AA50300000181030000010E0F061F0E9AA50300000181030000012AFE0F00282100000A2D090F00281B00000A2B01140F01282100000A2D090F01281B00000A2B01140F02282200000A2D090F02282300000A2B011628090000062A13300700D802000003000011022D0B7215000070732400000A7A022801000006732500000A0A066F2600000A2D0702732700000A7A732800000A0B032C03032B05721F0000701001066F1F00000A6F1100000A0C0603042D03162B01176F2900000A13051613063828010000110511069A0D071F0F8D010000011307110716168C1D000001A2110717096F2A00000AA2110718096F1F00000AA2110719096F1F00000A086F2B00000A178D1800000113081108167E1400000A9D11086F1800000AA211071A096F2C00000A6F2A00000AA211071B096F2C00000A6F1F00000AA211071C096F2C00000A6F1F00000A086F2B00000A178D1800000113091109167E1400000A9D11096F1800000AA211071D066F2D00000A6F2A00000AA211071E066F2D00000A6F1F00000AA211071F09096F2E00000A8C1E000001A211071F0A096F2F00000AA211071F0B096F3000000A8C1D000001A211071F0C096F3100000A8C03000001A211071F0D096F3200000A8C03000001A211071F0E096F3300000A8C03000001A211076F3400000A26110617581306110611058E693FCDFEFFFF0603042D03162B01176F3500000A130A16130B3820010000110A110B9A1304071F0F8D01000001130C110C16178C1D000001A2110C1711046F2A00000AA2110C1811046F1F00000AA2110C1911046F1F00000A086F2B00000A178D18000001130D110D167E1400000A9D110D6F1800000AA2110C1A11046F3600000A6F2A00000AA2110C1B11046F3600000A6F1F00000AA2110C1C11046F3600000A6F1F00000A086F2B00000A178D18000001130E110E167E1400000A9D110E6F1800000AA2110C1D11046F2D00000A6F2A00000AA2110C1E11046F2D00000A6F1F00000AA2110C1F09166A8C1E000001A2110C1F0B168C1D000001A2110C1F0C11046F3100000A8C03000001A2110C1F0D11046F3200000A8C03000001A2110C1F0E11046F3300000A8C03000001A2110C6F3400000A26110B1758130B110B110A8E693FD5FEFFFF072A1E02283700000A2A42534A4201000100000000000C00000076322E302E35303732370000000005006C000000D4040000237E0000400500000C06000023537472696E6773000000004C0B00002400000023555300700B0000100000002347554944000000800B0000AC0A000023426C6F620000000000000002000001471502080900000000FA0133001600000100000024000000020000000A00000022000000370000001C0000000300000001000000010000000200000000000A00010000000000060041003A000A00870072000600D1003A000600F900E6000A00050172000A005101360106009201730106004F023D02060066023D02060083023D020600A2023D020600BB023D020600D4023D020600EF023D0206000A033D02060023037301060037037301060045033D0206005E033D0206009B037B030600BB037B030600E4033A0006000C04020406003C043A000A006804360106009D0402040600A70402040600BF0402040600DB043A000600E3043A000A00E9043601060009053A0006002A05020406004505E60006004F05020406005805020400000000010000000000010001000100100019001E00050001000100502000000000910048000A000100B02000000000910059000F000200F22000000000960091001500040005210000000096009F001C0006001F21000000009600B300150009003721000000009600C30015000B005021000000009100DA0025000D00182200000000960010014B001D0058220000000091001401560020003C250000000086181B015E002300000001002101000001002601000002003101000000000000000001002101000000000000000001002601000002003101000000000000000001002101000000000000000001002101000001006301020002006701020003009F0102000400210102000500A40102000600B10102000700260102000800BC0102000900CF0102000A00D80102000B00E10102000C00E60102000D00F00102000E00FB0102000F00080202001000170200000100210100000200250200000300330200000100210100000200250200000300330231001B015E0039001B015E0041001B01880049001B01880051001B01880059001B01880061001B01880069001B01880071001B01880079001B01880081001B018D0089001B01880091001B01880099001B018800A1001B019200A9001B015E00B100EB039700B100F6039B00B9001104A000B9002504A000B1004104A300B1004804A900B90050040A00B1005C04A900B1006104B400C9001B015E0011007B043002110085043402B90091040A00D100B504A106E100CE043002F9001B015E001100FE04C9092900FE04C90929007B04C90901011B018800D9001B018800E1001F05C90909011B01880011011B015E00D9006505CD09E1006E053002B1007705D80919018105DD09D9008F05DD091901EB03E209E100980530021901A605C909E100B505E609E100C605E609E100D905E6091101EB05EB09D900EF05F009D900FE05DD0909001B015E002E0083008B0A2E0033002D0A2E003B001D0A2E007300750A2E001B001D0A2E0023002D0A2E002B002D0A2E007B00820A2E004300330A2E004B002D0A2E005B002D0A2E0063004B0A6000D300BC008000D3003A0284000B006200A000D300B503A4000B006200C000D3002C05C4000B006200E4000B00620000010301AF0604010B00620024010B00620044010B00620064010B00620084010B006200A4030B007500C4030B007500AF00AA06FA09A706048000000100000000000000000000000000D9030000020000000000000000000000010031000000000002000000000000000000000001006600000000000000003C4D6F64756C653E0046696C6553797374656D2E646C6C004E5446530053514C5365727665724672616D65776F726B006D73636F726C69620053797374656D004F626A6563740063735F4E6F726D616C697A65506174680063735F4275696C64506174680053797374656D2E446174610053797374656D2E446174612E53716C54797065730053716C537472696E67004E6F726D616C697A6550617468004275696C644E6F726D616C697A656450617468004765745061746846696C656E616D650047657450617468506172656E74004461746554696D65004469725F46696C6C526F770053797374656D2E436F6C6C656374696F6E730049456E756D657261626C650053716C426F6F6C65616E004469720063735F446972002E63746F72007061746800706172656E7450617468006974656D004D6963726F736F66742E53716C5365727665722E5365727665720053716C4661636574417474726962757465006F626A0069734469726563746F72790053797374656D2E52756E74696D652E496E7465726F705365727669636573004F7574417474726962757465006E616D650072656C61746976655061746800706172656E744E616D650072656C6174697665506172656E745061746800726F6F744E616D6500726F6F74506174680073697A6500657874656E73696F6E006973526561644F6E6C79006372656174696F6E54696D65006C61737441636365737354696D65006C617374577269746554696D65007365617263685061747465726E007265637572736976650053797374656D2E5265666C656374696F6E00417373656D626C795469746C6541747472696275746500417373656D626C794465736372697074696F6E41747472696275746500417373656D626C79436F6E66696775726174696F6E41747472696275746500417373656D626C79436F6D70616E7941747472696275746500417373656D626C7950726F6475637441747472696275746500417373656D626C79436F7079726967687441747472696275746500417373656D626C7954726164656D61726B41747472696275746500417373656D626C7943756C7475726541747472696275746500436F6D56697369626C65417474726962757465004775696441747472696275746500417373656D626C7956657273696F6E41747472696275746500417373656D626C7946696C6556657273696F6E4174747269627574650053797374656D2E52756E74696D652E436F6D70696C6572536572766963657300436F6D70696C6174696F6E52656C61786174696F6E734174747269627574650052756E74696D65436F6D7061746962696C6974794174747269627574650046696C6553797374656D00537472696E67006765745F4C656E67746800546F4368617241727261790053797374656D2E494F005061746800566F6C756D65536570617261746F7243686172004469726563746F7279536570617261746F7243686172004368617200436F6E636174005472696D456E640047657446756C6C50617468005472696D00466F726D61740053716C4D6574686F64417474726962757465006765745F56616C7565006F705F496D706C696369740047657446696C654E616D65004469726563746F7279004469726563746F7279496E666F00476574506172656E740046696C6553797374656D496E666F006765745F46756C6C4E616D6500426F6F6C65616E00496E7436340053716C46756E6374696F6E417474726962757465006765745F49734E756C6C00417267756D656E744E756C6C457863657074696F6E006765745F457869737473004469726563746F72794E6F74466F756E64457863657074696F6E0041727261794C6973740046696C65496E666F005365617263684F7074696F6E0047657446696C6573006765745F4E616D6500537562737472696E67006765745F4469726563746F7279006765745F526F6F74006765745F457874656E73696F6E006765745F4973526561644F6E6C79006765745F4372656174696F6E54696D65006765745F4C61737441636365737354696D65006765745F4C617374577269746554696D6500416464004765744469726563746F72696573006765745F506172656E740000000000137B0030007D007B0031007D007B0032007D000009700061007400680000032A00000083429548DEFB1A439C47D1C7E45172340008B77A5C561934E0890400010E0E0500020E0E0E06000111091109080002110911091109250010011C1002100E100E100E100E100E100E100E100E100A100E100210110D10110D10110D0A0003121111091109111507000312110E0E020320000112010001005408074D617853697A650002000012010001005408074D617853697A65A00F0000042001010E04200101020420010108032000080420001D030206030500020E1C1C0520010E1D030407011D030700040E0E1C1C1C81720100060054020F497344657465726D696E6973746963015402094973507265636973650154020A4F6E4E756C6C43616C6C005455794D6963726F736F66742E53716C5365727665722E5365727665722E446174614163636573734B696E642C2053797374656D2E446174612C2056657273696F6E3D322E302E302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D623737613563353631393334653038390A446174614163636573730000000054557F4D6963726F736F66742E53716C5365727665722E5365727665722E53797374656D446174614163636573734B696E642C2053797374656D2E446174612C2056657273696F6E3D322E302E302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D623737613563353631393334653038391053797374656D4461746141636365737300000000540E044E616D651666735F6E7466735F6E6F726D616C697A655F706174680320000E05000111090E81790100060054020F497344657465726D696E6973746963015402094973507265636973650154020A4F6E4E756C6C43616C6C005455794D6963726F736F66742E53716C5365727665722E5365727665722E446174614163636573734B696E642C2053797374656D2E446174612C2056657273696F6E3D322E302E302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D623737613563353631393334653038390A446174614163636573730000000054557F4D6963726F736F66742E53716C5365727665722E5365727665722E53797374656D446174614163636573734B696E642C2053797374656D2E446174612C2056657273696F6E3D322E302E302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D623737613563353631393334653038391053797374656D4461746141636365737300000000540E044E616D651D66735F6E7466735F6275696C645F6E6F726D616C697A65645F7061746881750100060054020F497344657465726D696E6973746963015402094973507265636973650154020A4F6E4E756C6C43616C6C005455794D6963726F736F66742E53716C5365727665722E5365727665722E446174614163636573734B696E642C2053797374656D2E446174612C2056657273696F6E3D322E302E302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D623737613563353631393334653038390A446174614163636573730000000054557F4D6963726F736F66742E53716C5365727665722E5365727665722E53797374656D446174614163636573734B696E642C2053797374656D2E446174612C2056657273696F6E3D322E302E302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D623737613563353631393334653038391053797374656D4461746141636365737300000000540E044E616D651966735F6E7466735F6765745F706174685F66696C656E616D6581730100060054020F497344657465726D696E6973746963015402094973507265636973650154020A4F6E4E756C6C43616C6C005455794D6963726F736F66742E53716C5365727665722E5365727665722E446174614163636573734B696E642C2053797374656D2E446174612C2056657273696F6E3D322E302E302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D623737613563353631393334653038390A446174614163636573730000000054557F4D6963726F736F66742E53716C5365727665722E5365727665722E53797374656D446174614163636573734B696E642C2053797374656D2E446174612C2056657273696F6E3D322E302E302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D623737613563353631393334653038391053797374656D4461746141636365737300000000540E044E616D651766735F6E7466735F6765745F706174685F706172656E74050001126D0E021D1C0407011D1C8318010007005455794D6963726F736F66742E53716C5365727665722E5365727665722E446174614163636573734B696E642C2053797374656D2E446174612C2056657273696F6E3D322E302E302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D623737613563353631393334653038390A4461746141636365737300000000540E1146696C6C526F774D6574686F644E616D650B4469725F46696C6C526F7754020F497344657465726D696E69737469630054020949735072656369736501540E044E616D650B66735F6E7466735F64697254557F4D6963726F736F66742E53716C5365727665722E5365727665722E53797374656D446174614163636573734B696E642C2053797374656D2E446174612C2056657273696F6E3D322E302E302E302C2043756C747572653D6E65757472616C2C205075626C69634B6579546F6B656E3D623737613563353631393334653038391053797374656D4461746141636365737301000000540E0F5461626C65446566696E6974696F6E818B6469726563746F72795F666C204249540D0A2C206E616D65204E564152434841522834303030290D0A2C2070617468204E564152434841522834303030290D0A2C2072656C61746976655F70617468204E564152434841522834303030290D0A2C20706172656E745F6E616D65204E564152434841522834303030290D0A2C20706172656E745F70617468204E564152434841522834303030290D0A2C2072656C61746976655F706172656E745F70617468204E564152434841522834303030290D0A2C20726F6F745F6E616D65204E564152434841522834303030290D0A2C20726F6F745F70617468204E564152434841522834303030290D0A2C2073697A6520424947494E540D0A2C20657874656E73696F6E204E564152434841522834303030290D0A2C20726561645F6F6E6C795F666C204249540D0A2C206372656174696F6E5F74696D65204441544554494D450D0A2C206C6173745F6163636573735F74696D65204441544554494D450D0A2C206C6173745F77726974655F74696D65204441544554494D45032000020A20021D12808D0E1180910420010E08042000126D0320000A042000110D042001081C0920021D126D0E11809122070F126D1280890812808D126D1D12808D081D1C1D031D031D126D081D1C1D031D030F01000A46696C6553797374656D000005010000000017010012436F7079726967687420C2A920203230303900002901002432396530346263352D643336372D343636352D386363392D62316233313338303665393200000C010007312E302E302E3000000801000800000000001E01000100540216577261704E6F6E457863657074696F6E5468726F7773010000983B00000000000000000000AE3B0000002000000000000000000000000000000000000000000000A03B00000000000000005F436F72446C6C4D61696E006D73636F7265652E646C6C0000000000FF250020400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100100000001800008000000000000000000000000000000100010000003000008000000000000000000000000000000100000000004800000058400000C00200000000000000000000C00234000000560053005F00560045005200530049004F004E005F0049004E0046004F0000000000BD04EFFE00000100000001000000000000000100000000003F000000000000000400000002000000000000000000000000000000440000000100560061007200460069006C00650049006E0066006F00000000002400040000005400720061006E0073006C006100740069006F006E00000000000000B00420020000010053007400720069006E006700460069006C00650049006E0066006F000000FC010000010030003000300030003000340062003000000040000B000100460069006C0065004400650073006300720069007000740069006F006E0000000000460069006C006500530079007300740065006D0000000000300008000100460069006C006500560065007200730069006F006E000000000031002E0030002E0030002E003000000040000F00010049006E007400650072006E0061006C004E0061006D0065000000460069006C006500530079007300740065006D002E0064006C006C00000000004800120001004C006500670061006C0043006F007000790072006900670068007400000043006F0070007900720069006700680074002000A900200020003200300030003900000048000F0001004F0072006900670069006E0061006C00460069006C0065006E0061006D0065000000460069006C006500530079007300740065006D002E0064006C006C000000000038000B000100500072006F0064007500630074004E0061006D00650000000000460069006C006500530079007300740065006D0000000000340008000100500072006F006400750063007400560065007200730069006F006E00000031002E0030002E0030002E003000000038000800010041007300730065006D0062006C0079002000560065007200730069006F006E00000031002E0030002E0030002E003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000C000000C03B00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

WITH PERMISSION_SET = EXTERNAL_ACCESS
GO
